package com.example.ordersystem;


import android.os.Bundle;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.ordersystem.pojo.Food;

import com.example.ordersystem.utils.LikeFoodAdapter;
import com.example.ordersystem.utils.Like_Food;
import com.example.ordersystem.utils.ListDataSave;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/*
 * 收藏页面
 */
public class LikeFoodFragment extends Fragment {
    private List<Food> list;

    private List<Food> like_food = new ArrayList<>();

    private HashMap<String, List<Food>> map = new HashMap<>();

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.like_food, container, false);


        String username = ListDataSave.getUserLogin(getContext());
        if (!username.equals("LoginOut")) {

            like_food = Like_Food.getLike_Food();
            //用map集合存储用户和用户所喜爱的菜品
            map.put(username, like_food);

            ListDataSave.putUserFoodLike(getContext(), map, username);

            HashMap<String, List<Food>> userFoodLikeList = ListDataSave.getUserFoodLikeList(getContext(), username);

            list = userFoodLikeList.get(username);

            final LikeFoodAdapter likeFoodAdapter = new LikeFoodAdapter(getActivity(), R.layout.like_food_list, this.list);

            ListView listView = view.findViewById(R.id.like_list_view);

            listView.setAdapter(likeFoodAdapter);

        }

        return view;
    }

}
